package com.eqdd.yiqidian.ui.gongneng.renshi.yuangongdangan.yuangongzhuangkuang;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.YuangongDocumentActivityCustom;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.ZaizhiRenyuanListResultBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class YuangongDocumentActivity extends BaseActivity {
    private YuangongDocumentActivityCustom dataBinding;
    private SlimAdapterEx slimAdapterEx;
    private ZaizhiRenyuanListResultBean bean;
    private ArrayList<SlimEditHintBean> datas;
    private SimpleDateFormat sf;
    private Date inviteDate;
    private Date birthDate;
    private ArrayList<LocalMedia> localMedias;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_yuangong_document);
        initTopTitleBar(View.VISIBLE, "员工档案");
    }

    @Override
    public void initData() {
        bean = (ZaizhiRenyuanListResultBean) getIntent().getSerializableExtra(Config.ZAIZHIYUANGONG_INFO);

        sf = new SimpleDateFormat("yyyy-MM-dd");
        dataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_28, new SlimInjector<SlimEditHintBean>() {
            @Override
            public void onInject(SlimEditHintBean data, IViewInjector injector) {
                injector.text(R.id.tv_left_content, dealText(data.getTitle()))
                        .text(R.id.tv_right_hint_content, dealText(data.getContent()));
            }
        }).attachTo(dataBinding.recyclerView);
        ImageUtil.setImage(bean.getUidumfrontphoto(), dataBinding.iv1);
        ImageUtil.setImage(bean.getUidumbackphoto(), dataBinding.iv2);
        ImageUtil.setImage(bean.getUwithidumphoto(), dataBinding.iv3);
        ImageUtil.setImage(bean.getUiphoto(), dataBinding.iv4);
        localMedias = new ArrayList<>();
        localMedias.add(new LocalMedia(bean.getUidumfrontphoto(), 0, PictureMimeType.ofImage(), PictureConfig.IMAGE));
        localMedias.add(new LocalMedia(bean.getUidumbackphoto(), 0, PictureMimeType.ofImage(),PictureConfig.IMAGE));
        localMedias.add(new LocalMedia(bean.getUwithidumphoto(), 0, PictureMimeType.ofImage(),PictureConfig.IMAGE));
        localMedias.add(new LocalMedia(bean.getUiphoto(), 0, PictureMimeType.ofImage(),PictureConfig.IMAGE));
    }

    private String dealText(String text) {
        return TextUtils.isEmpty(text) ? "" : text;
    }

    @Override
    public void setView() {
        try {
            inviteDate = sf.parse(bean.getInviteTime());
            birthDate = sf.parse(bean.getUdate());
        } catch (ParseException e) {
            e.printStackTrace();
        }

        datas = new ArrayList<>();
        datas.add(new SlimEditHintBean("姓名", bean.getUname(), 0));
        datas.add(new SlimEditHintBean("部门", bean.getDepartName(), 1));
        datas.add(new SlimEditHintBean("公司名称", bean.getCompanyName(), 2));
        datas.add(new SlimEditHintBean("手机号", bean.getUserPhone(), 3));
        datas.add(new SlimEditHintBean("入职时间", sf.format(inviteDate), 4));
        datas.add(new SlimEditHintBean("户口类型", bean.getUhousetype(), 5));
        datas.add(new SlimEditHintBean("户籍地址", bean.getUhouseadress(), 6));
        datas.add(new SlimEditHintBean("性别", bean.getUsex() == 0 ? "男" : "女", 7));
        datas.add(new SlimEditHintBean("民族", bean.getUnation(), 8));
        datas.add(new SlimEditHintBean("出生日期", sf.format(birthDate), 9));
        datas.add(new SlimEditHintBean("婚姻状况", bean.getUmarry(), 10));
        datas.add(new SlimEditHintBean("政治面貌", bean.getUpoliticstate(), 11));
        datas.add(new SlimEditHintBean("文化程度", bean.getUedu(), 12));
        datas.add(new SlimEditHintBean("专业", bean.getUmajor(), 13));
        slimAdapterEx.updateData(datas);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_1:
                PictureSelector.create(this).externalPicturePreview( 0, localMedias);
                break;
            case R.id.iv_2:
                PictureSelector.create(this).externalPicturePreview( 1, localMedias);
                break;
            case R.id.iv_3:
                PictureSelector.create(this).externalPicturePreview(  2, localMedias);
                break;
            case R.id.iv_4:
                PictureSelector.create(this).externalPicturePreview(  3, localMedias);
                break;
        }
    }
}
